package com.qf.flash.mvp.presenter;

import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.http.HttpManager;
import com.qf.flash.mvp.contract.BusOrderOptionContract;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.util.RxUtils;

/**
 * 描述: 商家操作
 * 2020/3/31 18:09
 */
public class BusOrderOptionPresenter extends BasePresenter<BusOrderOptionContract.View> implements BusOrderOptionContract.Presenter {

    @Override
    public void receiveOrRejectOrder(String orderId, int optionType) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .RECEIVE_REJECT(uid, orderId, optionType)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<Object>(mRootView) {
                    @Override
                    public void onSuccess(Object o) {
                        mRootView.receiveOrRejectOrderSuccess(optionType);
                    }
                })
        );
    }

    @Override
    public void shopOpCompleted(String orderId) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .SHOP_OP_COMPLETE(uid, orderId)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<Object>(mRootView) {
                    @Override
                    public void onSuccess(Object o) {
                        mRootView.shopOpCompletedSuccess();
                    }
                })
        );
    }

    @Override
    public void shopOpStartGame(String orderId) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .SHOP_OP_START_GAME(uid, orderId)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<Object>(mRootView) {
                    @Override
                    public void onSuccess(Object o) {
                        mRootView.shopOpStartGameSuccess();
                    }
                })
        );
    }

    @Override
    public void shopOpEndGame(String orderId) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .SHOP_OP_END_GAME(uid, orderId)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<Object>(mRootView) {
                    @Override
                    public void onSuccess(Object o) {
                        mRootView.shopOpEndGameSuccess();
                    }
                })
        );
    }

    @Override
    public void shopOpMoney(String orderId, double resetFee) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .SHOP_OP_MONEY(uid, orderId, resetFee)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<Object>(mRootView) {
                    @Override
                    public void onSuccess(Object o) {
                        mRootView.shopOpMoneySuccess();
                    }
                })
        );
    }
}
